<?php
class sessions extends CI_Controller{
	public function index()
	{
	
	}
	
	public function session($first = "", $second = "", $third = "")
	{
		$postData = $this->decoder->Decode();
		//echo $first . " " . $second . " " . $third;
		
		$content = md5(microtime().rand());
		
		if ( $first == "")
		{
			// Add user
			if ( $_SERVER['REQUEST_METHOD'] == "POST" )
			{
				//add to dba 
				if ($postData->session->ip != "")
				{
					$ip = $postData->session->ip;
					
					$this->load->model('session_m');
					$this->session_m->iduser = null;
					$this->session_m->ip = $ip;
					$this->session_m->content = $content;
					
					$session->iduser = null;
					$session->ip = $ip;
					$session->content = $content;
					
					echo json_encode(array("session" => $this->session_m));
					
					$this->load->library('session');
					$this->session->Insert($this->session_m);
				}
				//echo '{ "session": { "content" : "12345678901234567890123456789012" } }';
			}
		}
		else
		if ( $first == "bycontent" )
		{
			if ( $second != "" )
			{
				if ($_SERVER['REQUEST_METHOD'] == "GET" )
				{
					$this->load->library("session");
					
					$session = $this->session->GetByContent($second);
					
					echo $this->decoder->Code(array("session" => $session));
					
					//var_dump($session);
				}
			}
		}
		else
		{
		
		}

		
		
	}
}
?>